package com.javabasic.algorithm.sword_of_offer;

import org.junit.Test;

import java.util.ArrayList;

/**
 * @Author xiongmin
 * @ClassName 从尾到头打印链表
 * @Description TODO
 * @Date 2019/9/7 22:07
 * @Version 1.0
 **/
public class 从尾到头打印链表 {

    @Test
    public void main() {

    }

    public ArrayList<Integer> printListFromTailToHead(ListNode listNode) {
        ArrayList<Integer> result = null;
        if (listNode == null) return  result;
        result = new ArrayList<Integer>();

        while (listNode != null) {
            result.add(0,listNode.val);
            listNode = listNode.next;
        }
        return result;

    }
}

class ListNode {
    int val;
    ListNode next = null;

    ListNode(int val) {
        this.val = val;
    }
}
